/**
 * @file LogLevel.cpp
 * @author  haifeng (haifengxiao@icloud.com)
 * @brief
 * @version 0.1
 * @date 2021-07-16
 *
 * @copyright Copyright (c) 2021
 *
 */

#include "LogLevel.h"

namespace Chen {
    namespace Log {

        const char* LogLevel::ToString(LogLevel::Level level) {
            switch (level)     {
#define CASE(name)              \
    case LogLevel::name:        \
        return #name;           \
        break;

                CASE(DEBUG_);
                CASE(INFO);
                CASE(WARN);
                CASE(ERROR);
                CASE(FATAL);
#undef CASE    
            default:
                return "UNKNOW";
            }
            return "UNKNOW";
        }

        LogLevel::Level LogLevel::FromString(const std::string& str) {
#define TRANSFER(level, v)      \
    if (str == #v)              \
    {                           \
        return LogLevel::level; \
    }
            TRANSFER(DEBUG_, debug);
            TRANSFER(INFO, info);
            TRANSFER(WARN, warn);
            TRANSFER(ERROR, error);
            TRANSFER(FATAL, fatal);

            TRANSFER(DEBUG_, DEBUG);
            TRANSFER(INFO, INFO);
            TRANSFER(WARN, WARN);
            TRANSFER(ERROR, ERROR);
            TRANSFER(FATAL, FATAL);

            return LogLevel::Level::UNKNOW;
#undef TRANSFER
        }

    }//namespace Log
}//namespace Chen